<style>
.orderStatus {
	height: 20px;
	width: 20px;
	float: left;
	border-radius: 50%;
}
.orderStatusLabel {
	margin-top: 4px;
	float: left;
	padding-right: 10px; 
}
.normal {
	background: url("${rc.getContextPath()}/manage/images/green-yuan.png");
}
.overdueCompletion {
	background: url("${rc.getContextPath()}/manage/images/red-yuan.png");
}
.maybeOverdue {
	background: url("${rc.getContextPath()}/manage/images/yellow-yuan.png");
}
</style>
<div id="gridForProductionOrderOutput"></div>
<script>
(function($){
	var $page = DWZ.context(), $grid = $('#gridForProductionOrderOutput', $page),
	ecodes = JSON.parse('<#noescape>${ecodes!"[]"}</#noescape>'),
	orderTypes = JSON.parse('<#noescape>${orderTypes!"[]"}</#noescape>'),
	dateFmt = 'yyyy-MM-dd', timeFmt = 'yyyy-MM-dd HH:mm:ss',
	navTabId = '${navTabId!''}',
	statusCodes = ['normal', 'overdueCompletion', 'maybeOverdue'],
	statusTexts = {
		normal: '<@label key="normal.C">正常</@label>',
		maybeOverdue: '<@label key="maybeOverdue.C"></@label>',
		overdueCompletion: '<@label key="overdueCompletion.C"></@label>'
	},
	orderColumns = [
		{field: '_index', text: '<@label key="serialNumber.C">序号</@label>', width: 40},
		{field: 'productionOrderNum', text: "<@label key='productionOrderNum.C'>生产订单编号</@label>", defaultOrder: 'desc', css: 'toUp', width: 100, tdrender: function($td, obj){
			$td.empty().append($('<a class="link"/>').text(obj.productionOrderNum).on('click', function(event) {
				var ops = {
					mask: true,
					width: 860,
					height: 560,
					minable: false,
					resizable: false,
				}
				$.pdialog.open("${rc.getContextPath()}/manage/productionOutput/viewProductionControls?productionOrderNum=" + obj.productionOrderNum, "producionOrderDetails_output", "<@label key='view.B'>详情</@label>", ops);
				event.preventDefault();
			}));
		}},
		{field: 'productOrderNum', text: "<@label key='productOrderNum.C'>产品订单编号</@label>", width: 110, css: 'toUp'},
		{field: 'statuseCode', exportField: 'statuseText', text: "<@label key='orderStatusECode.C'>订单状态</@label>", width: 60, transform: function(value) {
			var text = '';
			$.each(ecodes, function(){
				if (value == this.eCode) {
					text = this.eCodeText;
				}
			});
			return text || value;
		}},
		{field: 'orderTypeText', text: "<@label key='orderType.C'>订单类型</@label>", width: 80},
		{field: 'materialCode', text: "<@label key='materialCode.C'>物料编号</@label>", width: 60, css: 'toUp'},
		{field: 'materialText', text: "<@label key='materialText.C'>物料名称</@label>", width: 80},
		{field: 'productionlotNum', text: "<@label key='productionlotNum.C'>生产批次号</@label>", width: 80},
		{field: 'processCode', text: "<@label key='cmprocess_code.C'>工艺编号</@label>", width: 60},
		{field: 'requirementDate', type: 'date', format: dateFmt, text: "<@label key='requirementDate.C'>需求日期</@label>", width: 80},
		{field: 'plannedendDateTime', type: 'date', format: timeFmt, text: "<@label key='plannedendDateTime.C'>计划结束时间</@label>", width: 120},
		{field: 'plannedQuantity', text: "<@label key='plannedQuantity.C'>计划数量</@label>", width: 60},
		{field: 'completedQuantity', text: "<@label key='completedQuantity.C'>完工数量</@label>", width: 60},
		{field: 'outputStatus', exportField: 'outputStatusText', text: "<@label key='status.C'>状态</@label>", width: 40, tdrender: function($td, obj) {
			var status = statusCodes[obj.outputStatus];
			$td.empty().append('<div title="' + statusTexts[status] + '" class="orderStatus ' + status + '" />');
		}}
	];
	
	orderTypes.unshift({orderTypeCode: '', orderTypeText: '<@label key="all.C">所有</@label>'});
	
	var orderStatusArr = [
		{value: '', label: '<@label key="all.C">所有</@label>'},
		{value: 0, label: "<@label key='normal.C'>正常</@label>"},
		{value: 1, label: "<@label key='overdueCompletion.C'>逾期未完成</@label>"},
		{value: 2, label: "<@label key='maybeOverdue.C'>可能逾期</@label>"}
	],
	queryfields = [
		orderColumns[5],
		orderColumns[6],
		{field: 'orderTypeCode', text: "<@label key='orderType.C'>订单类型</@label>", type: 'select', options: orderTypes, value: 'orderTypeCode', label: 'orderTypeText'},
		{field: 'outputStatus', text: "<@label key='status.C'>状态</@label>", type: 'select', options: orderStatusArr, change: function($this, $queryBar) {
			if ($this.val() == 2) {
				$('input[name=days]', $queryBar).removeAttr('readonly').removeClass('readonly').addClass('required').attr('min', 1);
			} else {
				$('input[name=days]', $queryBar).attr('readonly', true).removeClass('required').addClass('readonly').val('').next('.error').remove();
			}
		}},
		{field: 'days', text: "<@label key='warningDay.C'>预警天数</@label>", css: 'digits readonly', render: function($input) {
			$input.attr('readonly', true);
		}},
	];
	
	if (navTabId == 'PRODUCTION_OUTPUT') {
		queryfields.unshift(orderColumns[1]);
		orderColumns.splice(2, 1);
	} else {
		queryfields.unshift({field: 'productOrderNum', text: "<@label key='productOrderNum.C'>产品订单</@label>", css: 'toUp'});
	}
	
	$grid.jGrid({
		layoutH: 165,
		base: hostUrl + '/productionOutput/',
		url: 'getProductionOutputList',
		columns: orderColumns,
		//orderable: false,
		hasBorder: true,
		gridbars: [
			{icon: 'export', text: '<@label key="exportToExcel.D">导出</@label>', title: '<@label key="confirmexportToExcel.M"></@label>', 
			target: 'export', href: 'exportProductionOrdersToExcel', exportAll: true, data: {
				outputStatusMap: JSON.stringify({
					0: statusTexts.normal, 
					1: statusTexts.overdueCompletion,
					2: statusTexts.maybeOverdue
				})
			}, menuCode: 'PRODUCTOUTPUT_EXPORTTOEXCEL'}
		],
		getQueryData: function() {
			return navTabId == 'PRODUCTION_OUTPUT' ? {} : {productOrder: true};
		},
		query: {
			queryfields: queryfields,
			advancedqueryfields: [
				{field: 'productionlotNum', text: "<@label key='productionlotNum.C'>生产批次号</@label>"},
				{field: 'customer', text: '<@label key="customer.C">客户</@label>'},
	            {field: 'customerOrder', text: '<@label key="customerOrder.C">客户订单</@label>'},
	            {field: 'priority', text: '<@label key="priority.C">优先级</@label>', css: 'digits'}
			]
		}
	});
	
	var $legend = $('<li style="float: right; width: 260px;" />').appendTo($('<ul class="toolBar"/>').appendTo($('.headBar', $grid)));
	$legend.append('<div class="orderStatus normal"/>').append('<label class="orderStatusLabel">--' + statusTexts.normal + '</label>');
	$legend.append('<div class="orderStatus overdueCompletion"/>').append('<label class="orderStatusLabel">--' + statusTexts.overdueCompletion + '</label>');
	$legend.append('<div class="orderStatus maybeOverdue"/>').append('<label class="orderStatusLabel">--' + statusTexts.maybeOverdue + '</label>');
})(jQuery);
</script>